/**
 * Created by mapbar_front on 2019/8/2.
 */
import React,{Component} from 'react';
import ErrorBoundary from './../../components/ErrorBoundary';

function Example(){
    //throw new Error('I crashed!');
    //return <div>Ex</div>
}
// class ErrorExample extends Component{
//     render(){
//         return(
//             <ErrorBoundary>
//                 <Example/>
//             </ErrorBoundary>
//         )
//     }
// }


class ErrorExample extends Component{
    constructor(props){
        super(props);
        this.state = {
            error: false
        }
        this.handleClick = this.handleClick.bind(this);
    }
    handleClick=()=>{
        console.log('handleClick');
        try {
            // Do something that could throw
            throw new Error();
        } catch (error) {
            this.setState({ error });
        }
    }
    render(){
        if(this.state.error){
            return <h1>Caught an error.</h1>
        }
        return <div onClick={this.handleClick}>Click Me</div>
    }
}

export default ErrorExample;
